#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int n;
int sum = 0;       //解的总数

void dfs(int p, const vector<int>& col, const vector<int>& you, const vector<int>& zuo)
{
    if (p == n - 1)
    {
        for (int i = 0; i < n; i++)
        {
            if (find(col.begin(), col.end(), i) == col.end()
                && find(you.begin(), you.end(), p - i) == you.end()
                && find(zuo.begin(), zuo.end(), p + i) == zuo.end())
            {
                sum++;
                for (int i = 0; i < n; i++)
                {
                    if (i == 0)
                        cout << col[i];
                    else
                        cout << " " << col[i];
                }
                cout << endl;
            }
        }
    }
    else
    {
        for (int i = 0; i < n; i++)
        {
            if (find(col.begin(), col.end(), i) == col.end()
                && find(you.begin(), you.end(), p - i) == you.end()
                && find(zuo.begin(), zuo.end(), p + i) == zuo.end())
            {
                vector<int> s1 = col; s1.push_back(i);
                vector<int> s2 = you; s2.push_back(p - i);
                vector<int> s3 = zuo; s3.push_back(p + i);
                dfs(p + 1, s1, s2, s3);
            }
        }
    }
}



int main()
{
    cin >> n;
    vector<int>col;     //已经排的列数
    vector<int>you;     //
    vector<int>zuo;     //
    dfs(0, col, you, zuo);
}